package org.apache.tapestry5.internal.portlet.services.response;

import java.io.IOException;

import javax.portlet.PortletResponse;

import org.apache.tapestry5.Link;
import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.internal.portlet.services.PortletServicesMessages;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractPortletResponse implements
    org.apache.tapestry5.internal.portlet.services.response.PortletResponse, Response {

    private final Logger          _logger = LoggerFactory.getLogger(AbstractPortletResponse.class);

    private final PortletResponse _response;

    private final Request         _request;

    public AbstractPortletResponse(PortletResponse response, Request request) {
        assert response != null;
        assert request != null;

        this._response = response;
        this._request = request;
    }

    @Override
    public void sendRedirect(String URL) throws IOException {
        this._logger.error(PortletServicesMessages.unsupportedMethod("sendRedirect(URL)"));
    }

    @Override
    public void sendRedirect(Link link) throws IOException {
        this._logger.error(PortletServicesMessages.unsupportedMethod("sendRedirect(link)"));
    }

    @Override
    public void setStatus(int sc) {
        this._logger.error(PortletServicesMessages.unsupportedMethod("setStatus"));
    }

    @Override
    public void sendError(int statusCode, String message) throws IOException {
        this._logger.error(PortletServicesMessages.unsupportedMethod("sendError"));
    }

    @Override
    public void setContentLength(int contentLength) {
        this._logger.error(PortletServicesMessages.unsupportedMethod("setContentLength"));
    }

    @Override
    public void setDateHeader(String string, long date) {
        this._logger.error(PortletServicesMessages.unsupportedMethod("setDateHeader"));
    }

    @Override
    public void setHeader(String name, String value) {
        //    	_logger.error(PortletServicesMessages.unsupportedMethod("setHeader"));
        //    	LiferayPortletResponse liferayResponse = (LiferayPortletResponse) _response;
        //    	liferayResponse.getHttpServletResponse().setHeader(name, value);
        this._logger.info("Response Header: " + name + " " + value + " Class: " + this._response.getClass());
        //    	liferayResponse.setHeader(name, value);
    }

    @Override
    public void setIntHeader(String name, int value) {
        this._logger.error(PortletServicesMessages.unsupportedMethod("setIntHeader"));
    }

    @Override
    public String encodeURL(String url) {
        return this._response.encodeURL(url);
    }

    @Override
    public String encodeRedirectURL(String URL) {
        this._logger.error(PortletServicesMessages.unsupportedMethod("encodeRedirectURL"));

        return null;
    }

    @Override
    public void disableCompression() {
        this._request.setAttribute(InternalConstants.SUPPRESS_COMPRESSION, true);

    }

}